<?php
// 应用公共文件

use think\App;
use think\response\Json;
use app\service\basic\auth\Factory as AuthFactory;

if (!function_exists('amis')) {
    /**
     * 返回amis类型json
     *
     * @param array|object $data
     * @param string $msg
     * @param int $status
     * @param array $header
     * @param array $options
     * @return Json
     */
    function amis($data = [], string $msg = '操作成功', int $status = 0, array $header = [], array $options = []): Json
    {
        $response = [
            'data' => $data,
            'code' => $status,
            'message' => $msg,
        ];

        return json($response, 200, $header, $options);
    }
}

if (!function_exists('auth')) {
    /**
     * 获取身份认证实例
     *
     * @param null $guard
     * @return object|App
     */
    function auth($guard = null)
    {
        if (is_null($guard)) {
            return app(AuthFactory::class);
        }

        return app(AuthFactory::class)->guard($guard);
    }
}